package com.neusoft.databus.sap.ssh;

import java.io.IOException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.info.BuildProperties;
import org.springframework.stereotype.Component;

import sshd.shell.springboot.autoconfiguration.SshdShellCommand;

@Component
@SshdShellCommand(value = "system", description = "system information. Type 'system' for supported subcommands")
public class SystemCommand {

    @Autowired(required = false)
    private BuildProperties buildProperties;

    @SshdShellCommand(value = "build-info", description = "generate build information. Usage: system build-info")
    public String buildInfo(String arg) throws IOException {
        final StringBuilder builder = new StringBuilder();
        if (null != this.buildProperties) {
            builder.append("version: ").append(this.buildProperties.getVersion()).append("\n");
            builder.append("name: ").append(this.buildProperties.getName()).append("\n");
            builder.append("group: ").append(this.buildProperties.getGroup()).append("\n");
            builder.append("time: ").append(this.buildProperties.getTime()).append("\n");
            builder.append("artifact: ").append(this.buildProperties.getArtifact()).append("\n");
        } else {
            builder.append("no build information");
        }
        return builder.toString();
    }

}
